<template>
	<view @click="chooseLocation">
		<slot name="custom" v-if="$slots.custom" ></slot>
		<view class="t-flex" v-else :class="model?'c3':'c9'">
			{{ modelValue?modelValue.address:placeholder}} 
			<i class="iconfont icon-icchevronright f32"></i>
		</view>
	</view>
</template>

<script setup>
import { computed } from 'vue';
import { useStore } from '@/store';
	
	
	let emit = defineEmits(['update:modelValue'])
	const store = useStore()
	
	let props = defineProps({
		modelValue:{
			type:Object,
			default:{}
		},
		regeo:{  //是否逆解析地址
			type:Boolean,
			default:false
		},
		placeholder:{
			type:String,
			default:'请选择地址'
		}
	})
	
	
	let model = computed({
		get(){
			return props.modelValue
		},
		set(val){
			emit('update:modelValue',val)
		}
	})
	
	
	const chooseLocation = (e)=>{
		uni.chooseLocation({
			success(e) {
				if(props.regeo){
					store.getRegeo(e.latitude,e.longitude)
					.then(res=>{
						model.value = res
					})
				}else{
					model.value = e
				}
			},
			fail(e) {
				throw e.errMsg
			}
		})
	}
	
	
</script>

<style scoped lang="scss">

</style>
